<?php
namespace app\api\model;
use think\Model;
use think\model\concern\SoftDelete;
class TermEmergency extends Model
{
    use SoftDelete;
    protected $name = "term_emergency";
    protected $pk = "id";
    protected $deleteTime = "delete_time";
    protected $defaultSoftDelete = 0;
    protected $json = [];
    protected $jsonAssoc = true;
    public static function getNursingLang(array $eat=[],array $goto_toilet=[],array $operation=[],array $the_conduit=[],array $disease=[],array $sleeps=[]){
        $eat_ids = [];
        if(!empty($eat)){
            $eat_ids = DiseaseUser::where('name','in',$eat)
                ->where('type',1)
                ->where('status',1)
                ->column('id');
        }
        $goto_toilet_ids = [];
        if(!empty($goto_toilet)){
            $goto_toilet_ids = DiseaseUser::where('name','in',$goto_toilet)
                ->where('type',2)
                ->where('status',1)
                ->column('id');
        }
        $operation_ids = [];
        if(!empty($operation)){
            $operation_ids = DiseaseUser::where('name','in',$operation)
                ->where('type',3)
                ->where('status',1)
                ->column('id');
        }
        $the_conduit_ids = [];
        if(!empty($the_conduit)){
            $the_conduit_ids = DiseaseUser::where('name','in',$the_conduit)
                ->where('type',4)
                ->where('status',1)
                ->column('id');
        }
        $disease_ids = [];
        if(!empty($disease)){
            $disease_ids = DiseaseUser::where('name','in',$disease)
                ->where('type',5)
                ->where('status',1)
                ->column('id');
        }
        $sleeps_ids = [];
        if(!empty($sleeps)){
            $sleeps_ids = DiseaseUser::where('name','in',$sleeps)
                ->where('type',6)
                ->where('status',1)
                ->column('id');
        }
        $alldata = self::where('status',1)
            ->order('sort desc')
            ->select()->toArray();
//        $cyaji = function ($arr1,$arr2){
//            $chaji = array_diff($arr1,$arr2);
//            if(!empty($chaji)){
//                return false;
//            }else{
//                return true;
//            }
//        };
        foreach ($alldata as $value){
            if(!empty($eat_ids)){
                $array = explode(',',$value['eat']);
                $chaji = array_diff($eat_ids,$array);
                if(!empty($chaji)){
                    continue;
                }
            }
            if(!empty($goto_toilet_ids)){
                $array = explode(',',$value['goto_toilet']);
                $chaji = array_diff($goto_toilet_ids,$array);
                if(!empty($chaji)){
                    continue;
                }
            }
            if(!empty($operation_ids)){
                $array = explode(',',$value['operation']);
                $chaji = array_diff($operation_ids,$array);
                if(!empty($chaji)){
                    continue;
                }
            }
            if(!empty($the_conduit_ids)){
                $array = explode(',',$value['the_conduit']);
                $chaji = array_diff($the_conduit_ids,$array);
                if(!empty($chaji)){
                    continue;
                }
            }
            if(!empty($disease_ids)){
                $array = explode(',',$value['disease']);
                $chaji = array_diff($disease_ids,$array);
                if(!empty($chaji)){
                    continue;
                }
            }
            if(!empty($sleeps_ids)){
                $array = explode(',',$value['sleeps']);
                $chaji = array_diff($sleeps_ids,$array);
                if(!empty($chaji)){
                    continue;
                }
            }
//            echo '<pre>';
//            print_r(NursingLang::find($value['id'])->toArray());
//            exit;
            return NursingLang::find($value['id'])->toArray();
        }
        return NursingLang::find($alldata[0]['id'])->toArray();
    }
}